# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=osgQtQuick
pkgbase=mingw-w64-${_realname}-git
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}-git" "${MINGW_PACKAGE_PREFIX}-${_realname}-debug-git")
_ver_base=2.0.0
pkgver=2.0.0.r172
pkgrel=4
pkgdesc="OpenSceneGraph QML Modules (mingw-w64)"
arch=('any')
license=('LGPL')
url="https://github.com/podsvirov/osgqtquick"
makedepends=("make"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-osgQt"
             "${MINGW_PACKAGE_PREFIX}-osgQt-debug"
             "${MINGW_PACKAGE_PREFIX}-qt5")
options=(!strip staticlibs !buildflags)
source=(${_realname}::git+https://github.com/podsvirov/osgqtquick.git#branch=develop)
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "%s.r%s" "${_ver_base}" "$(git rev-list --count HEAD)"
}

build() {
  [[ -d ${srcdir}/release-${MINGW_CHOST} ]] && rm -rf ${srcdir}/release-${MINGW_CHOST}
  mkdir -p ${srcdir}/release-${MINGW_CHOST} && cd ${srcdir}/release-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    ../osgqtquick
  make

  [[ -d ${srcdir}/debug-${MINGW_CHOST} ]] && rm -rf ${srcdir}/debug-${MINGW_CHOST}
  mkdir -p ${srcdir}/debug-${MINGW_CHOST} && cd ${srcdir}/debug-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Debug \
    ../osgqtquick
}

package_release() {
  depends=("${MINGW_PACKAGE_PREFIX}-osgQt"
           "${MINGW_PACKAGE_PREFIX}-qt5"
           "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph")
  provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
  conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}" "${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
  replaces=(${MINGW_PACKAGE_PREFIX}-${_realname}-svn)

  cd ${srcdir}/release-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}

package_debug() {
  depends=("${MINGW_PACKAGE_PREFIX}-osgQt-debug"
           "${MINGW_PACKAGE_PREFIX}-qt5"
           "${MINGW_PACKAGE_PREFIX}-${_realname}-git=${pkgver}"
           "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph-debug")
  provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-debug")
  conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-debug" "${MINGW_PACKAGE_PREFIX}-${_realname}-debug-svn")
  replaces=(${MINGW_PACKAGE_PREFIX}-${_realname}-debug-svn)

  cd ${srcdir}/debug-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  rm -rf ${pkgdir}${MINGW_PREFIX}/include
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickConfig.cmake
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickConfigVersion.cmake
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickTargets.cmake
  rm -rf ${pkgdir}${MINGW_PREFIX}/share/qt5/qml/*/qmldir
}

package_mingw-w64-i686-osgQtQuick-git() {
  package_release
}

package_mingw-w64-i686-osgQtQuick-debug-git() {
  package_debug
}

package_mingw-w64-x86_64-osgQtQuick-git() {
  package_release
}

package_mingw-w64-x86_64-osgQtQuick-debug-git() {
  package_debug
}
